package com.aaa.product.service.impl;

import com.aaa.product.entity.TbPrdInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aaa.product.entity.TbActInf;
import com.aaa.product.dao.TbActInfMapper;
import com.aaa.product.service.TbActInfService;
@Service
public class TbActInfServiceImpl extends ServiceImpl<TbActInfMapper, TbActInf> implements TbActInfService{

    @Resource
    TbActInfMapper tbActInfMapper;
    @Resource
    RedisTemplate redisTemplate;

    public TbActInf findById(String tid) {
        return tbActInfMapper.selectById(tid);
    }

    public List<TbActInf> listByLname(String labelName) {
        QueryWrapper<TbActInf> travelsQueryWrapper = new QueryWrapper<>();
        travelsQueryWrapper.like("label_name", labelName);
        return this.list(travelsQueryWrapper);
    }

    public List<TbActInf> listDesc() {
        QueryWrapper<TbActInf> tbPrdInfoQueryWrapper = new QueryWrapper<>();
        // gt相当于>  ge>=    lt相当于<
        tbPrdInfoQueryWrapper.ge("finish_time",new Date());
        tbPrdInfoQueryWrapper.orderByDesc("update_date");
        return this.list(tbPrdInfoQueryWrapper);
    }


    /**
     * 获取当前时间的所有活动
     */
    @Override
    public List<TbActInf> selectTbActInfByNowTime(String time) {
        return redisTemplate.boundHashOps(time).values();
    }

    /**
     * 获取当前选中的活动详情
     *
     * @param time
     * @param tid
     */
    @Override
    public TbActInf selectTbActInfByNowTimeAndTid(String time, String tid) {
        return (TbActInf) redisTemplate.boundHashOps(time).get(tid);
    }
}
